<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('角色分配用户')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <input  type="hidden" name="id" id="id" th:value="${id}">
                <div class="select-list">
                    <ul>

                        <li>
                            角色名称：<input type="text" name="roleName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

<!--        <div class="btn-group-sm" id="toolbar" role="group">-->
<!--            <a class="btn btn-success" onclick="addStaff()">-->
<!--                <i class="fa fa-plus"></i> 添加-->
<!--            </a>-->
<!--        </div>-->

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "sso/staff/";
    $(function () {
        var options = {
            url: prefix+"/staffIdByRoleList",
            columns: [{
                checkbox: true
            },
                {
                    field: 'roleId',
                    title: '角色编号'
                },
                {
                    field: 'roleName',
                    title: '角色名称',
                    sortable: true
                },
                {
                    field: 'areaName',
                    title: '所属园区',
                    sortable: true
                },
                {
                    field: 'roleKey',
                    title: '权限字符',
                    sortable: true
                },
                {
                    field: 'roleSort',
                    title: '显示顺序',
                    sortable: true
                },
                {
                    visible: 'deleted',
                    title: '角色状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.deleted == 1) {
                            return '<span class="label label-danger">停用</span> ';
                        } else {
                            return '<span class="label label-success">正常</span>  ';
                        }
                    }
                },
                {
                    visible: 'isDefault',
                    title: '默认状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.isDefault == row.roleId) {
                            return '<span class="label label-danger">默认角色</span> ';
                        } else {
                            return '<span class="label label-success">非默认</span>  ';
                        }
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                }
                ,
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="setDefault(\'' + row.roleId + '\')"><i class="fa fa-edit"></i>设为默认</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="delStaffRole(\'' + row.roleId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }
                ]
        };
        $.table.init(options);
    });
    /* 修改 */
    function setDefault(roleId) {
        var id= $("#id").val();
        $.modal.confirm("确认要将此角色设为默认吗？", function() {
            $.operate.post( "/sso/role/setDefault", { "roleId": roleId,"staffId":id});
        })
    }


    function delStaffRole(roleId) {
        var id= $("#id").val();
        $.modal.confirm("确认要删除角色吗？", function() {
            $.operate.post(  "/sso/role/delStaffRole", { "roleId": roleId,"staffId":id});
        })
    }


</script>
</body>
</html>